REALEasyPrefs is a code module that contains several methods that fully automatize creating, saving and modifiying the preferences file for your application. REALEasyPrefs has methods to save and retrieve Numbers (integer), Doubles, Strings, Booleans, Colors, FolderItems and Windows (position and size).
Each item of data must have a unique name, that you later will use to retrieve or modify.
Usage:
· Drag the module to your project window.
· In the open event of you Application object or your main window call:
InitPrefFile(prefName as string)
where prefName is the name of your preferences file. ex.: "MyApp Prefs."
· In the Preferences dialog or anywhere in your App get or set preference items.
Find all the methods in the next section.
· In the close event of you Application object or your main window call:
WritePrefsFile()
This will save to the disk all the changes made to the preferences.
Methods for setting and getting preference items:
Every method has a fieldName parameter that you use to identify each preference item.
This means that you can Get/Set preferences in any order or in any place in your application.
Getting:
When getting you must specify a default value to return in case the preferences item with the given fieldName is not found.
· GetPrefNumber(fieldName as string,default as integer) As integer
· GetPrefString(fieldName as string,default as string) As string
· GetPrefBoolean(fieldName as string,default as boolean) As integer
· GetPrefColor(fieldName as string,default as color) As color
· GetPrefFolderItem(fieldName as string,default as FolderItem) As FolderItem
· GetPrefDouble(fieldName as string,default as Double) As Double
Setting:
· SetPrefNumber(fieldName as string,fieldValue as integer)
· SetPrefString(fieldName as string,fieldValue as string)
· SetPrefBoolean(fieldName as string,fieldValue as boolean)
· SetPrefColor(fieldName as string,fieldValue as Color)
· SetPrefFolderItem(fieldName as string,fieldValue as FolderItem)
· SetPrefDouble(fieldName as string,fieldValue as double)
Deleting:
· DeletePref(fieldName as string)
Windows:
· SetPrefWindow(fieldName as string,fieldValue as Window)
Saves the fieldValue Window position and size of the "fieldValue" window.
Use this method in the Close() event of the window you want to save SetPrefWindow("Win1",me).
· GetPrefWindow(fieldName as string,default as Window)
Retrieves the Window position and size saved under the "fieldName" name and sets it to the passed default window.
No value is returned.
Use this method in the Open() event of the window you want to restore GetPrefWindow("Win1",me).
When getting the windows position and size preferences no value is returned, instead the passed default window is modified according the values in the preferences file, if no field exists with the given "fieldName" the window is left untouched.
Try the sample project for a real example of how to use REALEasyPrefs.
Please, if you find this code useful drop me a note.